package org.unit.testmgmt.ui.actions;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.unit.testmgmt.base.UTMController;

/**
 * The base class for the actions.
 * 
 * @author Robert Streng
 *
 */
public abstract class UTMAction implements IObjectActionDelegate {

	protected Shell shell = null;
	protected IStructuredSelection selection = null;
	protected IWorkbenchWindow workbenchWindow = null;
	protected UTMController unitTestmgmt = null;
	
	
	/**
	 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
	 */
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		this.workbenchWindow = targetPart.getSite().getWorkbenchWindow();
		shell = workbenchWindow.getShell();		
	}
	
	/**
	 * @see IActionDelegate#selectionChanged(IAction, ISelection)
	 */
	public void selectionChanged(IAction action, ISelection selection) {
		if (selection instanceof IStructuredSelection)
			this.selection = (IStructuredSelection)selection;
	}
	
	/**
	 * @return UnitTestmgmt-main-controller
	 */
	protected UTMController getUTMController() {
		if (unitTestmgmt == null) {
			unitTestmgmt = new UTMController();
		}
		
		return unitTestmgmt;
	}
	
	@Override
	public void run(IAction action) {	
	}
	
}
